home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / amos / ldosv25d.lha / ldos_demo / examples / ldos / LineInput.AMOS / LineInput.amosSourceCode
AMOS Source Code  |  1992-07-11  |  3KB  |  106 lines

  1. Set Buffer 10
  2. '
  3. ' Dedicated to Andy Whitely who thoought Lload and Lstr was a bit  
  4. ' rough to use, and Line Input much to slow. Using these two procedures  
  5. ' You can 'emulate' AMOS's Line Input-command. To use it you must
  6. ' have LINESTART, LINESTOP (buffer "cursors"), SIZE (load-buffer given 
  7. ' in Kb), FEOF (internal procedure variable), CHAN (the channel you
  8. ' wish to use) and RAD$ (where the read line is placed) GLOBAL!  
  9. '
  10. ' To use these procedures, simply: 
  11. ' a) Set CHAN to a number between one and three
  12. ' b) Set SIZE to desired size. 4-8 Kb is enoough in most cases 
  13. ' c0)Set Lset Eoln To desired value (normally 10)
  14. ' c) Call _LINEOPEN with the filename
  15. ' d) Check Param for errors
  16. ' e) Call _LINEINPUT in a loop, until Param is false.
  17. '
  18. ' RAD$ will hold your read line. The procedure automatically calls 
  19. ' Free every time the buffer is re-filled (ie. another block is
  20. ' loaded) to prevent AMOS from crashing due to garbage collection. 
  21. '
  22. ' Please note that these procedures erase and use buffer 8 (you might
  23. ' want to change that) and can't handle multiple files (unless you 
  24. ' re-write the routines :) 
  25. '
  26. ' Have fun with AMOS!
  27. '
  28. Global LINESTART,LINESTOP
  29. Global CHAN,RAD$,FEOF,SIZE
  30. '
  31. '
  32. Screen Open 1,640,256,2,Hires : Paper 0 : Clw 
  33. '
  34. CHAN=3 : Rem These you need to init 
  35. SIZE=4
  36.  Extension_10_022A 10
  37. '
  38. '---- Open a file for _Lineinput. CHAN is set to 3, buffer 4Kb.
  39. _LINEOPEN["df0:docs/LdosV21.doc"]
  40. If Not Param
  41.    Print "Error opening file!"
  42.    End 
  43. End If 
  44. Do 
  45.    _LINEINPUT
  46.    Exit If Not Param
  47. '   Print RAD$ : Rem Wait Key      
  48. Loop 
  49.  Extension_10_0016 CHAN
  50. '
  51. '
  52. Procedure _LINEINPUT
  53.    If LINESTART>=LINESTOP
  54.       If Not FEOF
  55.          Gosub _LOAD
  56.       Else 
  57.          SUC=False
  58.          Goto SLUT2
  59.       End If 
  60.    End If 
  61.    '
  62.    RAD$= Extension_10_006C(LINESTART To LINESTOP)
  63.    LINESTART=LINESTART+Len(RAD$)+1
  64.    If(LINESTART>=LINESTOP) and Not(FEOF) and(Peek(LINESTOP)<>10)
  65.       Gosub _LOAD
  66.       D$= Extension_10_006C(LINESTART To LINESTOP)
  67.       LINESTART=LINESTART+Len(D$)+1 : RAD$=RAD$+D$
  68.    End If 
  69.    SUC=True
  70.    Goto SLUT2
  71.    '
  72.    _LOAD:
  73.    DUMMY=Free
  74.    LINESTART=Start(8)
  75.    A= Extension_10_0024(CHAN,LINESTART,SIZE*1024)
  76.    If A<SIZE*1024
  77.       LINESTOP=LINESTART+A
  78.       FEOF=True
  79.    End If 
  80.    Return 
  81.    SLUT2:
  82. End Proc[SUC]
  83. Procedure _LINEOPEN[F$]
  84.    FEOF=False
  85.    Erase 8 : Reserve As Work 8,SIZE*1024 : Rem 4 Kb buffer
  86.    LINESTART=Start(8)
  87.    LINESTOP=LINESTART+SIZE*1024
  88.    If Not Exist(F$)
  89.       Goto SLUT
  90.    Else 
  91.       If Extension_10_018E(F$)>0 : Rem Dir
  92.          Goto SLUT
  93.       End If 
  94.    End If 
  95.    SUC=True
  96.    If Extension_10_0182(F$)<1
  97.       SUC=False
  98.    End If 
  99.     Extension_10_0006 CHAN,F$,0
  100.    A= Extension_10_0024(CHAN,LINESTART,SIZE*1024)
  101.    If A<SIZE*1024
  102.       LINESTOP=LINESTART+A
  103.       FEOF=True
  104.    End If 
  105.    SLUT:
  106. End Proc[SUC]